package com.wechat.service.cmds.ser;

import java.util.concurrent.CompletableFuture;

import com.swak.annotation.Flux;
import com.swak.annotation.FluxReference;
import com.wechat.annotation.Cmd;
import com.wechat.command.Command;
import com.wechat.command.CommandResult;
import com.wechat.command.Commands;
import com.wechat.network.NetworkChannel;
import com.wechat.ser.result.GetInfoResult;
import com.wechat.service.ContactServiceAsync;

/**
 * 处理获取好友信息请求
 * 
 * @author 618lf
 */
@Flux
@Cmd(command = Commands.Ser_GetInfo, name = "处理获取好友信息请求")
public class GetInfoHandler extends AbstractSerHandler {

	@FluxReference
	private ContactServiceAsync contactService;

	@Override
	public CompletableFuture<CommandResult> handle(NetworkChannel channel, Command command) {
		return this.contactService.get(command.getTo())
				.thenApply(contact -> new GetInfoResult().setId(contact.getId()).setName(contact.getNickName()))
				.thenApply(info -> CommandResult.success(info));
	}
}
